/**
 * Created with CLion.
 * Description: 左值、右值
 * User: loong
 * Date: 2020-09-06
 * Time: 10:37
 */

#include <iostream>
#include <thread>

using namespace std;

class X
{
private:
    int *data;

public:
    X()
        : data(new int[1000000])
    {
    
    }
    
    virtual ~X()
    {
    
    }
    
    X(const X &other)
        : data(new int[1000000])
    {
        std:
        copy(other.data, other.data + 1000000, data);
    }
    
    X(X &&other)
        : data(other.data)
    {
        other.data = nullptr;
    }
};

void do_stuff(X && x_)
{
    X a(x_);                //拷贝
    X b(std::move(x_));     //移动
}

int main(){
    //X x1;
    //X x2 = std::move(x1);
    //X x3 = static_cast<X &&>(x2);
    
    do_stuff(X());      //临时对象为右值，将右值绑定到右值引用上
    X x;
    do_stuff(x);            //左值不能绑定到右值引用上
}